#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_STUDENTS 100

// 定义体检信息结构体
struct Checkup {
	int student_id;
	char name[50];
	char gender[10];
	char department[50];
	int age;
	float height;
	float weight;
	float chest_size;
	char date[20];
};

// 定义病历信息结构体
struct MedicalRecord {
	int student_id;
	char name[50];
	char gender[10];
	char department[50];
	char diagnosis[100];
	char date[20];
};

// 学生健康档案
struct HealthRecord {
	struct Checkup checkup;
	struct MedicalRecord medical_record;
};

// 学生健康档案数据库
struct HealthRecord health_records[MAX_STUDENTS];
int num_records = 0;

// 函数声明
void registerRecord();//登记
void queryRecord();//查询
void printCheckup(struct Checkup record);//打印体检
void printMedicalRecord(struct MedicalRecord record);//打印病例


int main() {
	int choice;
	
	do {
		system("CLS");
		printf("\n\t\t  学生健康档案管理系统");
		printf("\n\t\t========================");
		printf("\n\t\t\t 1.登记");
		printf("\n\t\t\t 4.查询");
		printf("\n\t\t\t 0.退出");
		printf("\n\t\t========================");
		printf("\n\t\t  请输入选项：");
		scanf("%d", &choice);
		system("cls");
		
		switch (choice) {
		case 1:
			registerRecord();
			break;
		case 4:
			queryRecord();
			break;
		case 0:
			printf("谢谢使用！\n");
			break;
		default:
			printf("无效选项，请重新输入。\n");
		}
	} while (choice != 0);
	
	system("pause");
	
	return 0;
}

void registerRecord() {
	struct HealthRecord new_record;
	
	printf("请输入学号: ");
	scanf("%d", &new_record.checkup.student_id);
	printf("请输入姓名: ");
	scanf("%s", new_record.checkup.name);
	printf("请输入性别: ");
	scanf("%s", new_record.checkup.gender);
	printf("请输入系别: ");
	scanf("%s", new_record.checkup.department);
	printf("请输入年龄: ");
	scanf("%d", &new_record.checkup.age);
	printf("请输入身高: ");
	scanf("%f", &new_record.checkup.height);
	printf("请输入体重: ");
	scanf("%f", &new_record.checkup.weight);
	printf("请输入胸围: ");
	scanf("%f", &new_record.checkup.chest_size);
	printf("请输入体检日期: ");
	scanf("%s", new_record.checkup.date);
	
	printf("请输入诊断信息: ");
	scanf("%s", new_record.medical_record.diagnosis);
	printf("请输入病历日期: ");
	scanf("%s", new_record.medical_record.date);
	
	health_records[num_records++] = new_record;
	
	printf("登记成功！\n");
	
	system("pause");
}

void queryRecord() {
	int id, found = 0;
	
	printf("请输入要查询的学生学号: ");
	scanf("%d", &id);
	
	for (int i = 0; i < num_records; ++i) {
		if (health_records[i].checkup.student_id == id ) {
			printf("=== 体检信息 ===\n");
			printCheckup(health_records[i].checkup);
			
			printf("=== 病历信息 ===\n");
			printMedicalRecord(health_records[i].medical_record);
			
			found = 1;
			
			break;
		}
	}
	
	if (!found) {
		printf("未找到该学生的记录！\n");
	}
}

void printCheckup(struct Checkup record) {
	printf("学号: %d\n", record.student_id);
	printf("姓名: %s\n", record.name);
	printf("性别: %s\n", record.gender);
	printf("系别: %s\n", record.department);
	printf("年龄: %d\n", record.age);
	printf("身高: %.2f\n", record.height);
	printf("体重: %.2f\n", record.weight);
	printf("胸围: %.2f\n", record.chest_size);
	printf("体检日期: %s\n", record.date);
}

void printMedicalRecord(struct MedicalRecord record) {
	printf("学号: %d\n", record.student_id);
	printf("姓名: %s\n", record.name);
	printf("性别: %s\n", record.gender);
	printf("系别: %s\n", record.department);
	printf("诊断信息: %s\n", record.diagnosis);
	printf("病历日期: %s\n", record.date);
	system("pause");
}
